//
//  ZWComposeTextView.swift
//  ZWWeibo
//
//  Created by flyiron on 16/4/26.
//  Copyright © 2016年 flyiron. All rights reserved.
//

import UIKit

let topMargin:CGFloat = 8

class ZWComposeTextView: UITextView {

    override init(frame: CGRect, textContainer: NSTextContainer?) {
        super.init(frame: frame, textContainer: textContainer)
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override var font: UIFont?{
        didSet{
            self.placeholderLabel.font = font
        }
    }
    
    var placeholderLabelText:String?{
        didSet{
            self.placeholderLabel.text = placeholderLabelText
        }
    }
    private func setupUI(){
        addSubview(placeholderLabel)
        
        placeholderLabel.snp_makeConstraints { (make) in
            make.top.equalTo(topMargin)
            make.leading.equalTo(5)
            make.width.equalTo(SCREENW - 10)
            
        }
        
        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ZWComposeTextView.textDidChage), name: UITextViewTextDidChangeNotification, object: nil)
        
    }
    func textDidChage(){
        self.placeholderLabel.hidden = hasText()
    }
    
    // MARK: - 懒加载控件
    private lazy var placeholderLabel:UILabel = {
        let label = UILabel(textColor: UIColor.lightGrayColor(), fontSize: 12)
        label.numberOfLines = 0
        label.text = "老司机你带带我 我滴头发黑哎"
        return label
    }()
    
    deinit{
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }
}

